package com.itheima.actuator;

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName: HealthConfig
 * Description:
 * Date: 2023/03/21 PM 11:59:47
 * <p>
 * project: springboot
 * package: com.itheima.actuator
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
@Component
public class HealthConfig extends AbstractHealthIndicator {
    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        boolean condition = true;
        if (condition) {
            builder.withDetail("runTime", System.currentTimeMillis());
            Map<String, Object> infoMap = new HashMap<>(16);
            infoMap.put("buildTime", "2006");
            builder.withDetails(infoMap);
            // builder.up();
            builder.status(Status.UP);
        } else {
            builder.status(Status.OUT_OF_SERVICE);
            builder.withDetail("上线了吗？", "你做梦");
            // builder.down();
        }
    }
}
